package com.kede.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;


/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/3/31 11:54
 ***/
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class ResHttp<T> {


    /*
     * 状态码
     */
    private Integer code;

    /*
     * 提示信息
     */
    private String msg;

    /*
     * 结果数据
     */
    @JSONField(serialzeFeatures = SerializerFeature.WriteMapNullValue)
    private T data;

    public ResHttp(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResHttp(Integer code, T data){
        this.code = code;
        this.data = data;
    }

    public ResHttp(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResHttp ok(String msg){
        return new ResHttp<>(200,msg);
    }

    public static <T> ResHttp okData(T data){
        return new ResHttp<>(200,"操作成功",data);
    }

    public static ResHttp failMsg(String msg){
        return new ResHttp(501,msg);
    }

    public static ResHttp fail(){
        return new ResHttp(501,"操作失败");
    }

    public static ResHttp ok(){
        return ok("操作成功");
    }

    public static ResHttp code(Integer code,String msg){
        return new ResHttp(code,msg);
    }

    public static <T> ResHttp ok(T data,String msg){
        return set(200,msg,data);
    }

    public static <T> ResHttp set(Integer code,String msg,T data){
        return new ResHttp(code,msg,data);
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof ResHttp)) return false;
        final ResHttp<?> other = (ResHttp<?>) o;
        if (!other.canEqual((Object) this)) return false;
        final Object this$code = this.getCode();
        final Object other$code = other.getCode();
        if (this$code == null ? other$code != null : !this$code.equals(other$code)) return false;
        final Object this$msg = this.getMsg();
        final Object other$msg = other.getMsg();
        if (this$msg == null ? other$msg != null : !this$msg.equals(other$msg)) return false;
        final Object this$data = this.getData();
        final Object other$data = other.getData();
        if (this$data == null ? other$data != null : !this$data.equals(other$data)) return false;
        return true;
    }

    protected boolean canEqual(final Object other) {
        return other instanceof ResHttp;
    }

    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $code = this.getCode();
        result = result * PRIME + ($code == null ? 43 : $code.hashCode());
        final Object $msg = this.getMsg();
        result = result * PRIME + ($msg == null ? 43 : $msg.hashCode());
        final Object $data = this.getData();
        result = result * PRIME + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "ResHttp(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }
}
